package com.leetcode.题库.score1;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * @BelongsProject: LeetCode
 * @BelongsPackage: com.leetcode.题库.score1
 * @Author: lei
 * @CreateTime: 2024-03-11  20:47
 * @Description:
 * @Version: 1.0
 */
public class 攀登者 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            String a = scanner.nextLine();
            int num = scanner.nextInt();
            ArrayList<Integer> arrayList = new ArrayList<>();
            String[] split = a.split(",");
            int start = Integer.parseInt(split[0]);
            int end = Integer.parseInt(split[split.length - 1]);
            int count = 0;
            if (start == 0 || end == 0) {
                count += 1;
            }
            if (start > Integer.parseInt(split[1])) {
                arrayList.add(start);
            }
            if (end > (Integer.parseInt(split[split.length - 2]))) {
                arrayList.add(end);
            }
            for (int i = 1; i < split.length - 1; i++) {
                int current = Integer.parseInt(split[i]);
                int left = Integer.parseInt(split[i - 1]);
                int right = Integer.parseInt(split[i + 1]);
                if ((current > right) && (current > left)) {
                    arrayList.add(current);
                }
            }
            System.out.println(arrayList);
        }
    }
}
